package com.example.demo.controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xkx
 * @time 2019/3/14 22:43
 * @description
 */
@Slf4j
@RestController()
@RequestMapping("weixin")
public class WxController {

  @RequestMapping("/auth")
  public void wxAuth(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    String signature = request.getParameter("signature");
    String timestamp = request.getParameter("timestamp");
    String nonce = request.getParameter("nonce");
    String echostr = request.getParameter("echostr");
    System.out.println("signature:" + signature);
    System.out.println("timestamp:" + timestamp);
    System.out.println("nonce:" + nonce);
    System.out.println("echostr:" + echostr);
    PrintWriter pw = null;
    pw = response.getWriter();
    pw.append(echostr);
    pw.flush();
    log.info("微信访问我成功");
  }
}
